function IsNothing(field,error_msg)
{
	if (field.value.replace(/(^\s*)|(\s*$)/g, "") == "")
	{
		alert(error_msg);
		field.focus();
		return true;
	}
}
function checknumber(field,error_msg)
{
	var val = field.value;

	if(isNaN(val) )
	{
		if(error_msg.length > 0)
		{
			alert(error_msg);	
			if(typeof(clearValue) =="function"){
			    clearValue(field);
			}
			field.focus();
		
		}
		return true;
	}
	else 
	{
		return false;
	}
}

function checkdigit(field,error_msg)
{
	var val = field.value;
	if(isNaN(val))
	{
		if(error_msg.length > 0)
		{
			alert(error_msg);
			field.focus();
		}
		return true;
	}
	else 
	{
		if(val%1 != 0)
		{
			alert(error_msg);
			field.focus();
			return true;
		}
		else
		{
			return false;
		}
	}
}
function checkdate(field,error_msg)
{
	if(field.value != "")
	{
		var valueflag=field.value.replace(/(^\s+|\s+$)/g,"");
		if(valueflag!="")
		{
			var s = valueflag.replace(/[\d]{4,4}[\.\-\/]{1}[\d]{1,2}[\.\-\/]{1}[\d]{1,2}/g,"");
			if (s=="") //YYYY-MM-DD or YYYY-M-DD or YYYY-M-D or YYYY-MM-D
			{
				valueflag=valueflag.replace(/\-/g,"/");
				valueflag=valueflag.replace(/\./g,"/");
		
				var t=new Date(valueflag);
		
				var iYear=t.getYear();
				if (iYear<100) (iYear+=1900);
				var iMonth=t.getMonth()+1;
				var iDay=t.getDate();
		
				var ar = valueflag.split(/[/]/);
		
				if(ar[0] != iYear || ar[1] != iMonth || ar[2] != iDay)
				{
					//YYYY-MM-DD YYYY/MM/DD YYYY.MM.DD 
					alert(error_msg);
					field.focus();
					return true;
				}
				return false;
			}
			else
			{
				alert(error_msg);
				field.focus();
				return true;
			}
		}
		else
		{
			return false;
		}
	}
	else
	{
		return false;
	}
}
function checkemail(field,error_msg)// check email
{
	var checkflag = true;
	var retvalue;
	if(field.value != "")
	{
		if (window.RegExp)
		{
			var tempstring = "a";
			var exam = new RegExp(tempstring);
			if (tempstring.match(exam))
			{
				var ret1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
				var ret2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
				retvalue = (!ret1.test(field.value) && ret2.test(field.value));
			}
			else
			{
				checkflag = false;
			}
		}
		else
		{
			 checkflag = false;
		 }
		if (!checkflag) 
		{
			retvalue = ( (field.value != "") && (field.value.indexOf("@")) > 0 && (field.value.index.Of(".") > 0) );
		}
		if(retvalue) 
		{
			return false;
		}
		else
		{
			alert(error_msg);
			field.focus();
			return true;
		}
	}
	else
	{
		return false;
	}	
}


function Num()//
{
  var berr=false;
  if (!((event.keyCode>=48 && event.keyCode<=57))) berr=true;
  return !berr;
}
function money()//
{
  var berr=false;
  if (!((event.keyCode>=48 && event.keyCode<=57)||event.keyCode==46)) berr=true;
  return !berr;
}

function checkfilename(field,err_msg)
{/*
	var checkflag = true;
	var retvalue;
	if (window.RegExp)
	{
		var tempstring = "a";
		var exam = new RegExp(tempstring);
		if (tempstring.match(exam))
		{
			var ret1 = new RegExp("[a-zA-Z0-9]");
			var ret2 = new RegExp("[a-zA-Z0-9]");
			retvalue = (!ret1.test(field.value) && ret2.test(field.value));
		}
		else
		{
			checkflag = false;
		}
		if (!checkflag) 
		{
			retvalue = ( (field.value != "") && (field.value.index.Of(".") > 0) );
		}
		if(!retvalue)
		{
			alert(err_msg);
			field.focus();
			return true;
		}
	}	*/
	return false;
}

function checkstrone(field,error_msg)// check strone
{
	var checkflag = true;
	var retvalue;
	if(field.value != "")
	{
		if (window.RegExp)
		{
			var tempstring = "a";
			var exam = new RegExp(tempstring);
			if (tempstring.match(exam))
			{
				var ret1 = new RegExp("\!|\@\|\#|\%|\&|\-|\=|\;|\:|\'|\,|\/| select | update | delete | from | and | or | exec | insert | chr | mid | truncate | not | count ","i");
				var ret2 = /\^/;
				var ret3 = /\\/;
				var ret4 = /\$/;
				var ret5 = /\*/;
				var ret6 = /\(/;
				var ret7 = /\)/;
				var ret8 = /\+/;
				var ret9 = /\[/;
				var ret10 = /\]/;
				var ret11 = /\./;
				var ret12 = /\?/;
				retvalue = !(ret1.test(field.value)||ret2.test(field.value)||ret3.test(field.value)||ret4.test(field.value)||ret5.test(field.value)||ret6.test(field.value)||ret7.test(field.value)||ret8.test(field.value)||ret9.test(field.value)||ret10.test(field.value)||ret11.test(field.value)||ret12.test(field.value));
				//retvalue = !ret1.test(field.value);
			}
			else
			{
				checkflag = false;
			}
		}
		else
		{
			 checkflag = false;
		 }
		if (!checkflag) 
		{
			retvalue = ( (field.value != "") && (field.value.indexOf("@")) > 0 && (field.value.index.Of(".") > 0) );
		}
		
		if(retvalue) 
		{
			return false;
		}
		else
		{
			alert(error_msg);
			field.focus();
			return true;
		 }
	}
	else
	{
		return false;
	}
}

function checktitle(field,error_msg)// check email
{
	var checkflag = true;
	var retvalue;
	if(field.value != "")
	{
		if (window.RegExp)
		{
			var tempstring = "a";
			var exam = new RegExp(tempstring);
			if (tempstring.match(exam))
			{
				var ret1 = new RegExp("\'| select | update | delete | from | and | or | exec | insert | chr | mid | truncate | not | count ","i");
				retvalue = !ret1.test(field.value);
			}
			else
			{
				checkflag = false;
			}
		}
		else
		{
			 checkflag = false;
		 }
		if (!checkflag) 
		{
			retvalue = ( (field.value != "") && (field.value.indexOf("@")) > 0 && (field.value.index.Of(".") > 0) );
		}
		
		if(retvalue) 
		{
			return false;
		}
		else
		{
			alert(error_msg);
			field.focus();
			return true;
	    }
	}
	else
	{
		return false;
	}
}


function checkmobile(field,error_msg)// check email
{
	var checkflag = true;
	var telflag = 1;
	var retvalue;
	var i,j,strTemp,len;
	if(field.value != "")
	{
		if (window.RegExp)
		{
			var tempstring = "a";
			var exam = new RegExp(tempstring);
			if (tempstring.match(exam))
			{
				var ret1 = new RegExp("^13","i");
				var ret2 = new RegExp("^013","i");
				var ret3 = new RegExp("^15","i");
				var ret4 = new RegExp("^015","i");
				retvalue = ret1.test(field.value)||ret2.test(field.value)||ret3.test(field.value)||ret4.test(field.value);
			}
			else
			{
				checkflag = false;
			}
		}
		else
		{
			 checkflag = false;
		 }
		if (!checkflag) 
		{
			retvalue = ( (field.value != "") && (field.value.indexOf("@")) > 0 && (field.value.index.Of(".") > 0) );
		}
		
		if(retvalue) 
		{
			len=field.value.length;
			if(!(len==11 || len==12))
			{
				telflag=0;
			}
			strTemp="0123456789";
			for (i=0;i<len;i++)
			{
				j=strTemp.indexOf(field.value.charAt(i));
				if (j==-1)
				{
					telflag=0;
				}
			}
			if(telflag == 1)
			{
				return false;
			}
			else
			{
				alert(error_msg);
				field.focus();
				return true;
			}
		}
		else
		{
			alert(error_msg);
			field.focus();
			return true;
	    }
	}
	else
	{
		return false;
	}
}

function checkpwd(field,error_msg)// check strone
{
	var checkflag = true;
	var retvalue;
	if(field.value != "")
	{
		if (window.RegExp)
		{
			var tempstring = "a";
			var exam = new RegExp(tempstring);
			if (tempstring.match(exam))
			{
				var ret1 = new RegExp(" select | update | delete | from | and | or | exec | insert | chr | mid | truncate | not | count ","i");
				var ret2 = /\W/;
				retvalue = !(ret1.test(field.value)||ret2.test(field.value))
			}
			else
			{
				checkflag = false;
			}
		}
		else
		{
			 checkflag = false;
		 }
		if (!checkflag) 
		{
			retvalue = ( (field.value != "") && (field.value.indexOf("@")) > 0 && (field.value.index.Of(".") > 0) );
		}
		
		if(retvalue) 
		{
			return false;
		}
		else
		{
			alert(error_msg);
			field.focus();
			return true;
		 }
	}
	else
	{
		return false;
	}
}

//no checkbox be checked
function ischecked(error_msg)
{
	var iFlag=false;
    for (var i = 0; i < document.form1.elements.length; i++) 
    {
        if (document.form1.elements[i].type == "checkbox") 
        {
            if (document.form1.elements[i].checked==true) 
            {
                iFlag=true;
                break;
            }
        }
    }
    
    if(iFlag==true)
    {
        return false;
    }
    else
    {
        alert(error_msg);
        return true;
    }
}

function isboxchecked(error_msg,varName)
{
	var iFlag=false;
    for (var i = 0; i < document.form1.elements.length; i++) 
    {
        if (document.form1.elements[i].type == "checkbox" && document.form1.elements[i].name.indexOf(varName)>-1) 
        {
            if (document.form1.elements[i].checked==true) 
            {
                iFlag=true;
                break;
            }
        }
    }
    
    if(iFlag==true)
    {
        return false;
    }
    else
    {
        alert(error_msg);
        return true;
    }
}

function havacheck(formname,inputname,error_msg)
{
	var flag=0;
	for (var i=0;i<formname.length;i++)
	{
		if(formname[i].name==inputname)
		{
			if(formname[i].checked==true)
			{
				flag=1;
				break;
			}
		}
	}
			
	if(flag==1)
	{	
		return false;
	}
	else
	{
		alert(error_msg);
		return true;
	}
}

function checktel(field,error_msg)
{
	var i,j,strTemp,len;
	var flag=1;
	if(field.value!="")
	{
		len=field.value.length;
		if(len<7 || len>32)
		{
			flag=0;
		}
		strTemp="0123456789-()# ";
		for (i=0;i<len;i++)
		{
			j=strTemp.indexOf(field.value.charAt(i));
			if (j==-1)
			{
				flag=0;
			}
		}
		if(flag==0)
		{
			alert(error_msg);
			field.focus();
			return true;
		}
		else
		{
			return false;
		}
	}
	else
	{
		return false;
	}
}

function checkidcard(field,error_msg)
{
	var checkflag = true;
	var retvalue;
	if(field.value != "")
	{
		if (window.RegExp)
		{
			var tempstring = "a";
			var exam = new RegExp(tempstring);
			if (tempstring.match(exam))
			{
				var ret1 = /\W/;
				retvalue = !ret1.test(field.value)
			}
			else
			{
				checkflag = false;
			}
		}
		else
		{
			 checkflag = false;
		 }
		if (!checkflag) 
		{
			retvalue = ( (field.value != "") && (field.value.indexOf("@")) > 0 && (field.value.index.Of(".") > 0) );
		}
		
		if(retvalue && (field.value.length==15 || field.value.length==18)) 
		{
			return false;
		}
		else
		{
			alert(error_msg);
			field.focus();
			return true;
		 }
	}
	else
	{
		return false;
	}
}

function checkpostid(field,error_msg)
{
	var i,j,strTemp,len;
	var flag=1;
	if(field.value!="")
	{
		len=field.value.length;
		if(len!=6)
		{
			flag=0;
		}
		strTemp="0123456789";
		for (i=0;i<len;i++)
		{
			j=strTemp.indexOf(field.value.charAt(i));
			if (j==-1)
			{
				flag=0;
			}
		}
		if(flag==0)
		{
			alert(error_msg);
			field.focus();
			return true;
		}
		else
		{
			return false;
		}
	}
	else
	{
		return false;
	}
}

function isempty(field,error_msg)//there is nothing in the field of textarea
{
	var flag=0
	var str=field.value
	for(i=0;i<str.length;i++)
	{
		if(str.charCodeAt(i)!=13 && str.charCodeAt(i)!=10 && str.charCodeAt(i)!=32)
		{
			flag=1
			break;
		}
	}
	if(flag==0)
	{
		alert(error_msg);
		try
		{
		    field.focus();
		}
		catch(err)
		{
		}
		return true;
	}
	else
	{
		return false;
	}
}

